// JavaScript Document
var childwin = null;
function openWindow(url,w,h,sb){
  	var wh = document.body.clientHeight;
	var ww = document.body.clientWidth;
  	var wl = (ww - w) / 3;
  	var wt = (wh - h) / 3;
	childwin = window.open(url,'childwin','toolbar=no, menubar=no,location=no, status=no,scrollbars=' + sb + ',resizable=no,top=' + wt + ',left=' + wl + ', width='+ w +',height=' + h);
}

function openWindowM(url,w,h,sb){
  	var wh = document.body.clientHeight;
	var ww = document.body.clientWidth;
  	var wl = (ww - w) / 3;
  	var wt = (wh - h) / 3;
	childwin = window.open(url,'childwin','toolbar=no, menubar=yes,location=no, status=no,scrollbars=' + sb + ',resizable=no,top=' + wt + ',left=' + wl + ', width='+ w +',height=' + h);
}

function checkChildwin(){
  	if(childwin != null){
		if(!childwin.closed){
			childwin.focus();
		} else {
			childwin = null;
		}
  	}
}

function showmodaldiv(title, width, height, src, dac){	
	var d;
	d = window.top.document;
	var div_overlay = d.createElement("div");
	div_overlay.style.cssText = "text-align: center; width: 100%; height: " + d.body.scrollHeight + "px; position: absolute; top: 0px; left: 0px; z-index: 999; background-image:url(images/overlay.gif);";
	div_overlay.id="moduleDiv";	
	var div_modal = d.createElement("div");
	
	var div_modal_width = width;
	var div_modal_height = height;
	var div_modal_top = d.body.scrollTop + 100;
	
	div_modal.style.cssText = "position: relative; top: " + div_modal_top + "px; margin: auto; background-color: #fff; width: " + div_modal_width + "px; height: " + div_modal_height + "px; border: 1px solid #B9CED3;"
	
	var div_modal_title_height = 25;
	var div_modal_title = d.createElement("div");
	div_modal_title.style.cssText = "width: 100%; height: " + div_modal_title_height + "px; background-image: url(images/list_button_hover.jpg); text-align: left;";
	var div_title = d.createElement("div");
	div_title.style.cssText = "height: " + div_modal_title_height + "px; line-height: " + div_modal_title_height + "px; margin-left: 10px; font-weight: bold;";
	div_title.innerHTML = title;
	
	var div_close = d.createElement("div");
	div_close.style.cssText = "height: " + div_modal_title_height + "px; line-height: " + div_modal_title_height + "px; position: absolute; top: 0px; right: 0px; margin-right: 10px; cursor: pointer;";
	div_close.innerHTML = "|<font style='color:blue'>X</font>|";
	div_close.onclick = function(){
	    if(typeof dac != "function"){
	        alert("parameter dac is not a function!");
	    } else {
	        dac(div_modal_iframe);
	    }
		div_overlay.style.display = "none";
		div_overlay = null;		
	}
	
	div_modal_title.appendChild(div_title);
	div_modal_title.appendChild(div_close);
	var adjHeight = 2;
	div_modal_iframe_height = div_modal_height - div_modal_title_height - adjHeight;
	var div_modal_iframe = d.createElement("iframe");
	div_modal_iframe.style.cssText = "width: 100%; height: " + div_modal_iframe_height + "px;border: none; overflow-x: hidden;";
	div_modal_iframe.src = src;
	div_modal_iframe.scrolling = "yes";
	
	div_modal.appendChild(div_modal_title);
	div_modal.appendChild(div_modal_iframe);
	
	div_overlay.appendChild(div_modal);
	
	d.body.appendChild(div_overlay);
}

function goto(href){
    window.location = href;
}

function goBack(){
    window.history.go(-1);
}

function confirmSubmit(f,act,tip,v){
    if (confirm(tip)){
        formSubmit(f,act,v);
    }
}

function formSubmit(f,act,v){
    if(!v || v.validate()){
        var oaction = document.getElementById("navigate_action");
        oaction.value = act;
        f.submit();
    }
}

function confirmClick(alertMsg,url){
	if(confirm(alertMsg))
	{
		window.location=url;
	}
}

function alignBottom(divname){
    var obj = document.getElementById(divname);
    if(document.body.scrollHeight + obj.offsetHeight + 20 <= document.body.clientHeight) {
    	obj.style.top = document.body.clientHeight - obj.offsetHeight - 1;
    } else {
    	obj.style.top = document.body.scrollHeight + 20;
    }
}